﻿using System;
using Glue;
using Xunit;

namespace GlueTests.RelationsVerificationTests
{
    public class When_some_relations_are_a_nested_simplified_mapping
    {
        private readonly Mapping<DomainPerson, GuiPerson> mapping;
        private readonly IRelationsVerification verify;

        public class DomainPerson
        {
            public String Name { get; set; }
            public DomainAddress Address { get; set; }
        }
        public class DomainAddress
        {
            public String City { get; set; }
        }

        public class GuiPerson
        {
            public String Name { get; set; }
            public String City { get; set; }
        }

        public When_some_relations_are_a_nested_simplified_mapping()
        {
            mapping = new Mapping<DomainPerson, GuiPerson>();
            mapping.Relate(domain=>domain.Name,gui=>gui.Name);
            mapping.Relate(domain => domain.Address.City, gui => gui.City);

            verify = mapping.GetRelationsVerification();

        }

        [Fact]
        public void Should_verify_towards_flattened_type()
        {
            verify.AssertAllPropertiesRelated<GuiPerson>();
        }

        [Fact]
        public void Should_not_fail_if_nested_relations_are_related_through_simplified_mapping()
        {
            verify.AssertAllPropertiesRelated<DomainPerson>();
        }
    }
}
